package com.hzjh.base.ext.widget.recycleview

import com.hzjh.base.ext.R
import com.hzjh.base.ext.databinding.JhImageUpItemBinding
import com.hzjh.base.frame.adapter.BaseBindingVH
import com.hzjh.base.style.weight.GlideUtils.loadCenterCorp
import com.hzjh.base.utils.function.visibleOrGone
import com.hzjh.base.utils.other.CheckUtils

class JHImageUpItemVH(binding:JhImageUpItemBinding,
                      private val delete:(position:Int)->Unit,
                      private val add:()->Unit,
                      private val enable:()->Boolean ) : BaseBindingVH<String, JhImageUpItemBinding>(binding){
    override fun onBind(model: String, position: Int) {
        if(CheckUtils.isEmpty(model)){
            binding.ivImgItem.setImageResource(if(enable.invoke()) R.drawable.svg_add_img else com.hzjh.base.style.R.color.coreTransparent)
            binding.ivImgItem.setOnClickListener {
                //添加
                if(enable.invoke()) {
                    add.invoke()
                }
            }
        }else{
            binding.ivImgItem.loadCenterCorp(model)
            binding.ivImgItem.setOnClickListener(null)
        }
        binding.ivDeleteImg.visibleOrGone(!CheckUtils.isEmpty(model)&&enable.invoke()){
            setOnClickListener {
                //删除
                delete.invoke(position)
            }
        }
    }
}